Central Article

Migrating Your Flash Applications to Macromedia Central


Table of Contents

  1. Introduction
  2. New Features in Macromedia Central
  3. Things to Avoid and Watch Out For
  4. Testing and Debugging Your Application
  5. Enhancing Your Application
  6. Deploying Your Application

Things to Avoid and Watch Out For

When you develop your application there are a few things you need to watch out for. Some things just work differently within Central because of how the movie clip architecture is set up. Simple things like persistent global variables and intervals can slow down the performance of not only your application but other Central applications as well. It's up to the developer to make sure things run smoothly.

Avoid: _root

You've probably heard about this one for a while: Avoid references to _root. In fact, you may have a hard time migrating an existing application that relies heavily on the use of _root. Here's why: Because your application is loaded into a container clip, any references to _root are actuality referencing the top-level SWF, which is no longer your main application timeline. Here are a few suggestions for overcoming this variance in scope.

Create a global reference to the application's root. Then set up existing calls to root so they reference appRoot instead of _root:

_global.appRoot = this;

A more appropriate way of doing this might be to create a controller, which is a variable reference to the root of the application:

// appRoot._mc.sub_mc
appRoot._mc.sub_mc.appRoot = this;

Another option, provided by Fernando Flórez of Funciton, attempts to give you the _lockroot functionality of Flash Player 7. Although it looks like it could be a bit bulky, it seems to help automate things:

www.onelx.com/blog/en/archives/000166.php

There's always the option of hard-coding it all.

Adjusting your existing application to accompany this workaround could end up being a laborious task. With Flash MX 2004 however, the global Find and Replace comes in quite handy.

Watch Out: _global and prototypes

Although you can use _global, there are a few things you need to watch out for. Remember that the application shell, Console (notices/pods), and agent are run in separate instances of the Central Flash Player. You have to clean them up when switching between applications. Globals and prototypes persist within the application shell when switching between applications that come from the same domain. So when you use _global and prototypes within the agent and Console you may get conflicting namespaces, whether the user has two instances of your application's pod open or you have two application agents running from the same domain.

Best practices would create a unique namespace for each instance of a global variable or prototype:

_global.fooApplication = new Object();
_global.fooApplication.bar = "foobar';
// ...
function onDeactivate()
{
     delete _global.fooApplication;
}

Application developers are encouraged to avoid using the global scope.

Watch Out: setInterval

Remember that your application will not always be the only one running within Central. It's up to the developer to clean up any loose ends that may be hanging around if your application is uninstalled or deactivated. Intervals persist similarly to _global and prototypes. When someone switches from your application while an interval is running in the background, it continues to run; returning to your application may cause multiple instances of your interval to occur, producing undesirable results. Therefore, clear your intervals when your application is deactivated.

Example 1:

myInterval = setInterval(updateData, 300000);
// ...
function onDeactivate()
{
     clearInterval(myInterval);
}

Example 2:

function onDeactivate()
{
     for (var i = setInterval(Function, 1000); i >= 0; i--) 
{
     clearInterval(i);
}
}

Another way to help facilitate the management of your application's intervals is to create an interval manager by developing an object with methods that manage the setting and clearing of your intervals.

In addition, one preventative step when using intervals is to call clearInterval before your setInterval statement. Although it creates some overhead, it assures that you are not starting up multiple identical intervals (where clearInterval would not necessarily clear all intervals).

Watch Out: _mc.loadMovie

If you load a SWF, GIF, or JPEG from another domain into a movie clip, the movie clip is considered to be from another domain. This means your movie can no longer call methods on it unless the movie clip incorporates allowDomain() for your domain, which isn't possible with the two supported image formats. Using the global loadMovie(mc,...) or unloadMovie(mc,...) works, however.